<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: YKMZ
  Date: 2022/9/19
  Time: 17:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>pageContext作用域</title>
</head>
<body>
    <h1>Request作用域：【一次请求内有效：转发可取得值，重定向得不到值】</h1>
    <%
        //3. 再从当前页面取出数据
        List<String> books = (List<String>) request.getAttribute("books");
        //4. 打印图书
        if (books != null) {
            for (String book : books) {
                out.println(book + "<br>");
            }
        }else {
            out.println("重定向得到不值！");
        }
    %>
    <h1>session作用域：【浏览器cookie中存放sessionId,只要浏览器不关闭，就可以】
    <%
        //3. 再从当前页面取出数据
        books = (List<String>) session.getAttribute("books");
        out.println("sessionId:" + session.getId());
        //4. 打印图书
        if (books != null) {
            for (String book : books) {
                out.println(book + "<br>");
            }
        }
    %>
</body>
</html>
